package pro.cherish.knowledgeumldesignpattern.designPattern.com.cherish.singleton;

import java.io.ObjectStreamException;
import java.io.Serializable;

public class T06 implements Serializable{

    private static T06 instance=null;
    private T06(){
        if(instance!=null){
            throw new RuntimeException("手动抛出异常");
        }
    }
    public static synchronized T06 getInstance() {
        if (instance == null) {
            instance = new T06();
        }
        return instance;
    }

//    反序列化时，直接返回该对象,不需要将反序列化的新对象返回
    private Object readResolve ()throws ObjectStreamException{
        return instance;
    }
}
